package cn.gson.work.model.pojos;

import com.fasterxml.jackson.annotation.JsonFormat;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

@Entity
public class Project {
    private long pId;
    private Long userNo;
    private String pNo;
    private String pName;
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Timestamp pStar;
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Timestamp pEnd;
    private String pForm;
    private String pState;
    private Category categoryList;
    private User userList;
    private Collection<Budget> budgetsByys;
    private Collection<Profit> profits;

    @Id
    @Column(name = "P_ID")
    public long getpId() {
        return pId;
    }

    public void setpId(long pId) {
        this.pId = pId;
    }

    @Basic
    @Column(name = "USER_NO")
    public Long getUserNo() {
        return userNo;
    }

    public void setUserNo(Long userNo) {
        this.userNo = userNo;
    }

    @Basic
    @Column(name = "P_NO")
    public String getpNo() {
        return pNo;
    }

    public void setpNo(String pNo) {
        this.pNo = pNo;
    }

    @Basic
    @Column(name = "P_NAME")
    public String getpName() {
        return pName;
    }

    public void setpName(String pName) {
        this.pName = pName;
    }

    @Basic
    @Column(name = "P_STAR")
    public Timestamp getpStar() {
        return pStar;
    }

    public void setpStar(Timestamp pStar) {
        this.pStar = pStar;
    }

    @Basic
    @Column(name = "P_END")
    public Timestamp getpEnd() {
        return pEnd;
    }

    public void setpEnd(Timestamp pEnd) {
        this.pEnd = pEnd;
    }

    @Basic
    @Column(name = "P_FORM")
    public String getpForm() {
        return pForm;
    }

    public void setpForm(String pForm) {
        this.pForm = pForm;
    }

    @Basic
    @Column(name = "P_STATE")
    public String getpState() {
        return pState;
    }

    public void setpState(String pState) {
        this.pState = pState;
    }

    @ManyToOne
    @JoinColumn(name = "C_ID", referencedColumnName = "C_ID")
    public Category getCategoryList() {
        return categoryList;
    }

    public void setCategoryList(Category categoryList) {
        this.categoryList = categoryList;
    }



    @ManyToOne
    @JoinColumn(name = "USER_NO", insertable=false ,updatable=false)
    public User getUserList() {
        return userList;
    }

    public void setUserList(User userList) {
        this.userList = userList;
    }

    @OneToMany(mappedBy = "project")
    public Collection<Budget> getBudgetsByys() {
        return budgetsByys;
    }

    public void setBudgetsByys(Collection<Budget> budgetsByys) {
        this.budgetsByys = budgetsByys;
    }

    @OneToMany(mappedBy = "project")
    public Collection<Profit> getProfits() {
        return profits;
    }

    public void setProfits(Collection<Profit> profits) {
        this.profits = profits;
    }









    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Project project = (Project) o;
        return pId == project.pId &&
                Objects.equals(userNo, project.userNo) &&
                Objects.equals(pNo, project.pNo) &&
                Objects.equals(pName, project.pName) &&
                Objects.equals(pStar, project.pStar) &&
                Objects.equals(pEnd, project.pEnd) &&
                Objects.equals(pForm, project.pForm) &&
                Objects.equals(pState, project.pState);
    }

    @Override
    public int hashCode() {
        return Objects.hash(pId, userNo, pNo, pName, pStar, pEnd, pForm, pState);
    }

    @Override
    public String toString() {
        return "Project{" +
                "pId=" + pId +
                ", userNo=" + userNo +
                ", pNo='" + pNo + '\'' +
                ", pName='" + pName + '\'' +
                ", pStar=" + pStar +
                ", pEnd=" + pEnd +
                ", pForm='" + pForm + '\'' +
                ", pState='" + pState + '\'' +
                ", categoryList=" + categoryList +
                ", userList=" + userList +
                '}';
    }
}
